package com.ershui.blog.boke.controller;

import com.ershui.blog.article.domain.LCategory;
import com.ershui.blog.boke.domain.*;
import com.ershui.blog.boke.service.BlogService;
import com.ershui.blog.system.controller.BaseController;
import com.ershui.blog.system.domain.AjaxResult;
import com.ershui.blog.system.domain.TableDataInfo;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Blog")
public class BlogController extends BaseController {
    @Autowired
    private BlogService blogService;

    @GetMapping("/articleCount")
    public AjaxResult GetArticleCount(BlogArticleInDto inDto){
        Integer pageCount= blogService.selectArticleCount(inDto);
        return AjaxResult.sucess("查询成功",pageCount);
    }

    @GetMapping("/articleList")
    public TableDataInfo GetArticleList(BlogArticleInDto inDto){
        startPage();
        List<BlogArticleOutDto> articles=blogService.selectArticlesByParam(inDto);
        return getDataTable(articles);
    }

    @GetMapping("/categoryList")
    @ResponseBody
    public  AjaxResult SelectCategorys(){
        List<LCategory> data=blogService.selectCategorys();
        return AjaxResult.sucess("查询成功",data);
    }


    @PutMapping("/articleDetail")
    public AjaxResult ViewArticleDetail(Long id){
        BlogArticleOutDto article=blogService.viewArticle(id);
        return AjaxResult.sucess("查询成功",article);
    }

    @PostMapping("/addLeaveWords")
    public AjaxResult AddLeaveWords(@RequestBody LLeaveWords leaveWords, HttpServletRequest request){
        blogService.insertLeaveWords(leaveWords,request);
        return AjaxResult.sucess();
    }

    @GetMapping("/getLeaveWords")
    public AjaxResult GetLeaveWords(LeaveWordsInDto inDto){
        List<LeaveWordsOutDto> leaveWordsList=blogService.GetLeaveWords(inDto);
        return AjaxResult.sucess("查询成功",leaveWordsList);
    }

    @GetMapping("/getHotArticle")
    public AjaxResult SelectHotArticleTitle(){
        List<BlogArticleOutDto> data=blogService.selectHotArticle();
        return AjaxResult.sucess("查询成功",data);
    }

    @GetMapping("/getDiary")
    public AjaxResult SelectDiaryList(){
        List<SelectDiaryOutDto> list=blogService.selectDiayList();
        return AjaxResult.sucess("查询成功",list);
    }
}
